/*----------------------------------------------------------------------
  - File name      : STC8Ax_PCA.h
  - Author         : Quark Team
  - Update date    : 2020-12-09                   
  -	Copyright      : Gevico Electronic studio   
  - Module comments: Header file of PCA module.
-----------------------------------------------------------------------*/
#ifndef __STC8Ax_PCA_H_
#define __STC8Ax_PCA_H_
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
/*--------------------------------------------------------
| @Description: STC8Ax Options                           |
--------------------------------------------------------*/
#include "STC8Ax_REG.h"   
/*--------------------------------------------------------
| @Description: STC8Ax core                              |
--------------------------------------------------------*/
#include "STC8Ax_CORE.h"
/*-----------------------------------------------------------------------
|                                 DATA                                  |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: PCA mode enum                            |
--------------------------------------------------------*/

typedef enum
{
    PCA_TYPE_PWM = 0x42,
    PCA_TYPE_TIM = 0x48,
    PCA_TYPE_POP = 0x4C
}   PCAType_Type;

/*--------------------------------------------------------
| @Description: PCA clock mode enum                      |
--------------------------------------------------------*/

typedef enum
{
	PCA_SCLK_DIV_12 = 0x00,  //  System clock / 12
	PCA_SCLK_DIV_2  = 0x02,  //  System clock / 2
	PCA_TIMER0		  = 0x04,  //  Overflow pulse of timer 0
	PCA_ECI         = 0x06,  //  External input clock of ECI pin
	PCA_SCLK_DIV_1	= 0x08,  //  System clock / 1
	PCA_SCLK_DIV_4  = 0x0A,  //  System clock / 4
	PCA_SCLK_DIV_6  = 0x0C,  //  System clock / 6
	PCA_SCLK_DIV_8  = 0x0E   //  System clock / 8
}	PCACLKSrc_Type;

/*--------------------------------------------------------
| @Description: PCA PWM bits mode enum                   |
--------------------------------------------------------*/

typedef enum
{
	PCA_PWM_8Bit = 0,   // 8-bit PCA_PWM mode
	PCA_PWM_7Bit    ,	// 7-bit PCA_PWM mode
	PCA_PWM_6Bit    ,	// 6-bit PCA_PWM mode
	PCA_PWM_10Bit	 	//10-bit PCA_PWM mode
}	PCA_PWMBits_Type;


/*-----------------------------------------------------------------------
|                             API FUNCTION                              |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: PCA Counter working function             |
--------------------------------------------------------*/

FSCSTATE PCA_CNT_Init(PCACLKSrc_Type CLKSrc,uint16 Value,FUNSTATE Run);

/*--------------------------------------------------------
| @Description: PCA PWM mode working function            |
--------------------------------------------------------*/

FSCSTATE PCA0_PWM_Init(PCA_PWMBits_Type PWMBits,uint16 Duty);
FSCSTATE PCA1_PWM_Init(PCA_PWMBits_Type PWMBits,uint16 Duty);
FSCSTATE PCA2_PWM_Init(PCA_PWMBits_Type PWMBits,uint16 Duty);
FSCSTATE PCA3_PWM_Init(PCA_PWMBits_Type PWMBits,uint16 Duty);

/*--------------------------------------------------------
| @Description: PCA TIMER mode working function          |
--------------------------------------------------------*/

FSCSTATE PCA0_TIM_Init(uint16 Value);
FSCSTATE PCA1_TIM_Init(uint16 Value);
FSCSTATE PCA2_TIM_Init(uint16 Value);
FSCSTATE PCA3_TIM_Init(uint16 Value);

/*--------------------------------------------------------
| @Description: PCA POP mode working function            |
--------------------------------------------------------*/

FSCSTATE PCA0_POP_Init(uint16 Value);
FSCSTATE PCA1_POP_Init(uint16 Value);
FSCSTATE PCA2_POP_Init(uint16 Value);
FSCSTATE PCA3_POP_Init(uint16 Value);

/*--------------------------------------------------------
| @Description: PCA PWM and POP reload value function    |
--------------------------------------------------------*/

void PCA0_TIM_POP_ReValue(void);
void PCA1_TIM_POP_ReValue(void);
void PCA2_TIM_POP_ReValue(void);
void PCA3_TIM_POP_ReValue(void);


/*--------------------------------------------------------
| @Description: PCA control define function              |
--------------------------------------------------------*/

#define    PCA0_WORK_STOP()   CCAPM0 = 0
#define    PCA1_WORK_STOP()   CCAPM1 = 0
#define    PCA2_WORK_STOP()   CCAPM2 = 0
#define    PCA3_WORK_STOP()   CCAPM3 = 0

#endif
/*-----------------------------------------------------------------------
|          END OF FLIE        (C) COPYRIGHT Gevico Electronics          | 
-----------------------------------------------------------------------*/

